<?php

namespace Bjkl8\Controller;

class DaxiaoSearchjsonController extends CommonController {
	
	
	function search() {
		/*
		 * 参数： $disnum:定码个数(1) 
		 * $zhouqi:计划周期 
		 * $weishu:定码位数(1-5:个十百千万) 
		 * $sch_gs_num:搜索的公式数量 
		 * $sch_sl:计划目标准确率 
		 * $sch_zhouqi:计划已完成周期 
		 * $sch_zhouqi_sy:计划当前周期剩余：（1） 
		 * $sch_max_lian_gua:计划历史最大连错 
		 * $sch_lian_gua:计划当前连错 
		 * $sch_max_lian_zhong:计划历史最大连对 
		 * $sch_lian_zhong:计划当前连对
		 * $gongshi:从第n条公式开始搜索(1-25)
		 */
		if(I('sch_gs_num')){
			$sch_gs_num=I('sch_gs_num');//搜索的公式数量
		}else{
			$sch_gs_num=10;//搜索的公式数量
		}
		if(I('sch_sl')){
			$sch_sl=I('sch_sl');//计划目标准确率
		}else{
			$sch_sl=0;//计划目标准确率
		}
		if(I('sch_zhouqi')){
			$sch_zhouqi=I('sch_zhouqi');//计划已完成周期
		}else{
			$sch_zhouqi=20;
		}
		// 			$sch_zhouqi_sy=1;//计划当前周期剩余：（1）
		if(I('sch_max_lian_gua')){
			$sch_max_lian_gua=I('sch_max_lian_gua');//计划历史最大连错
		}else{
			$sch_max_lian_gua=30;
		}
		if(I('sch_max_lian_gua')){
			$sch_lian_gua=I('sch_lian_gua');//计划当前连错
		}else{
			$sch_lian_gua=30;
		}
		if(I('sch_max_lian_zhong')){
			$sch_max_lian_zhong=I('sch_max_lian_zhong');//计划历史最大连对
		}else{
			$sch_max_lian_zhong=0;
		}
		if(I('sch_lian_zhong')){
			$sch_lian_zhong=I('sch_lian_zhong');//计划当前连对
		}else{
			$sch_lian_zhong=0;
		}
		// 周期
		if (I ( "zhouqi" ) == null) {
			$zhouqi = 3;
		} else {
			$zhouqi = I ( "zhouqi" );
		}
		// 定码
		if (I ( "disnum" ) == null) {
			$disnum = 4;
		} else {
			$disnum = I ( "disnum" );
		}
		// 位数
		if (I ( "weishu" ) == null) {
			$weishu = 1; // 个位
		} else {
			$weishu = I ( "weishu" );
		}
		if(I("gongshi")){
			$gongshi = I("gongshi");
		}else{
			$gongshi = 1;
		}
		if (I ( "zqnum" ) == null) {
			$zqnum = 30;
		} else {
			$zqnum = I ( "zqnum" );
		}
		$this->search_data($sch_gs_num,$sch_sl,$sch_zhouqi,$sch_max_lian_gua,$sch_lian_gua,$sch_max_lian_zhong,$sch_lian_zhong,$zhouqi,$disnum,$weishu,$gongshi,$zqnum);
	
	}
	
	function search_data($sch_gs_num=10,$sch_sl=0,$sch_zhouqi=20,$sch_max_lian_gua=30,$sch_lian_gua=30,$sch_max_lian_zhong=0,$sch_lian_zhong=0,$zhouqi=3,$disnum=4,$weishu=1,$gongshi=1,$zqnum=20){
		$json_result = array (); // 返回结果集
		while ( $gongshi < 25 ) {
			//获取公式表名
			$gongshi_m = bjkl8_num_to_gongshi($gongshi);
			//获取位数
			$weishu_arr = bjkl8_num_to_weishu($weishu);
			// 获取当天的所有推荐
			$result_tjsj = bjkl8_get_new_tj($gongshi_m);
			//获取定码统计列表
			$result_arr = bjkl8_get_daxiao_data($result_tjsj, $weishu_arr, $disnum, $zhouqi);
			//统计结果
			$result_sl = bjkl8_get_tongji_search($result_arr, $zqnum, $disnum, $zhouqi, $gongshi, $weishu, $sch_sl, $sch_zhouqi, $sch_max_lian_gua, $sch_lian_gua, $sch_max_lian_zhong, $sch_max_lian_zhong, $sch_lian_zhong, $sch_gs_num);
	
			// 按条件选择
			if (($result_sl ['sl'] >= $sch_sl) && ($sch_zhouqi <= $zqnum) && ($result_sl ['max_lian_gua'] <= $sch_max_lian_gua) && ($result_sl ['lian_gua'] <= $sch_lian_gua) && ($result_sl ['max_lian_zhong'] >= $sch_max_lian_zhong) && ($result_sl ['lian_zhong'] >= $sch_lian_zhong)) {
				array_push ( $json_result, $result_sl );
			}
			// 如果获取足够则返回数据
			if (count ( $json_result ) >= $sch_gs_num) {
				break;
			}
			$gongshi ++;
	
		}
		//结果返回
		$json_result_return['list']=$json_result;
		echo json_encode ( $json_result_return, JSON_UNESCAPED_UNICODE );
	}
}








